From 2d5d7b4e4713eca7211fa138a9ea3ea0b7873777 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 9 Sep 2014 15:01:31 -0700 Subject: [PATCH] Add a NUM_JOBS env var to builds Closes #539 --- src/cargo/ops/cargo_rustc/context.rs | 2 ++ src/doc/source/native-build.md | 2 ++ tests/test_cargo_compile.rs | 1 + 3 files changed, 5 insertions(+) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 35714b163..bb5e88301 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -151,6 +151,8 @@ impl<'a, 'b> Context<'a, 'b> { self.build_requirements(pkg, target, Target, &mut HashSet::new()); } + self.compilation.extra_env.insert("NUM_JOBS".to_string(), + Some(self.config.jobs().to_string())); self.compilation.root_output = self.layout(KindTarget).proxy().dest().clone(); self.compilation.deps_output = self.layout(KindTarget).proxy().deps().clone(); diff --git a/src/doc/source/native-build.md b/src/doc/source/native-build.md index 03bda2b01..bc253fa89 100644 --- a/src/doc/source/native-build.md +++ b/src/doc/source/native-build.md @@ -71,6 +71,8 @@ commands. * `OUT_DIR` - the folder in which all output should be placed. * `TARGET` - the target triple that is being compiled for. Native code should be compiled for this triple. +* `NUM_JOBS` - the parallelism specified as the top-level parallelism. This can + be useful to pass a `-j` parameter to a system like `make`. * `DEP__OUT_DIR` - This variable is present for all immediate dependencies of the package being built. The `` will be the package's name, in uppercase, with `-` characters diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 1caf58335..976dab449 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -791,6 +791,7 @@ test!(custom_build_env_vars { .file("src/foo.rs", format!(r#" use std::os; fn main() {{ + let _ncpus = os::getenv("NUM_JOBS").unwrap(); let out = os::getenv("OUT_DIR").unwrap(); assert!(out.as_slice().starts_with(r"{0}")); assert!(Path::new(out).is_dir()); -- 2.30.2